package com.example.mall.web.controller;

import com.example.mall.domain.ReceivedMessages;
import com.example.mall.dto.ReceivedMessagesDto;
import com.example.mall.exception.ErrorEnumCode;
import com.example.mall.exception.GlobalCustomerException;
import com.example.mall.query.PageDTO;
import com.example.mall.query.ReceivedMessagesQuery;
import com.example.mall.result.JSONResult;
import com.example.mall.service.IReceivedMessagesService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/receivedMessages")
public class ReceivedMessagesController {

    @Autowired
    public IReceivedMessagesService receivedMessagesService;

    /**
     * 分页查询接收消息表信息
     * @param receivedMessagesQuery
     * @return
     */
    @GetMapping("queryPage")
    @ApiOperation(value = "分页查询接收消息表信息",notes = "分页查询接收消息表信息",httpMethod = "GET")
    public JSONResult queryPage(ReceivedMessagesQuery receivedMessagesQuery){
        PageDTO<ReceivedMessagesDto> receivedMessagesDtoPageDTO = receivedMessagesService.queryPage(receivedMessagesQuery);
        return JSONResult.success("查询成功",receivedMessagesDtoPageDTO);
    }

    /**
     * 根据id查询接收消息表信息
     * @param receivedId
     * @return
     */
    @GetMapping("query/{receivedId}")
    @ApiOperation(value = "根据id查询接收消息表信息",notes = "根据id查询接收消息表信息",httpMethod = "GET")
    public JSONResult query(@PathVariable("receivedId")Long receivedId){
        //1.根据id查询用户信息
        if (receivedId == null){
            throw new GlobalCustomerException(ErrorEnumCode.RECEIVEDID_NOT_ID);
        }
        ReceivedMessages receivedMessages = receivedMessagesService.getById(receivedId);
        return JSONResult.success("查询成功",receivedMessages);
    }

    /**
     * 根据id查询接收消息表信息
     * @param receivedId
     * @return
     */
    @GetMapping("queryReceivedMessagesById/{receivedId}")
    @ApiOperation(value = "根据id查询接收消息表信息",notes = "根据id查询接收消息表信息",httpMethod = "GET")
    public JSONResult queryReceivedMessagesById(@PathVariable("receivedId")Long receivedId){
        //1.根据id查询用户信息
        if (receivedId == null){
            throw new GlobalCustomerException(ErrorEnumCode.RECEIVEDID_NOT_ID);
        }
        ReceivedMessages receivedMessages = receivedMessagesService.queryReceivedMessagesById(receivedId);
        return JSONResult.success("查询成功",receivedMessages);
    }

    /**
     * 查询全部接收消息表信息
     * @param
     * @return
     */
    @GetMapping("queryReceivedMessagesList")
    @ApiOperation(value = "查询全部接收消息表信息",notes = "查询全部接收消息表信息",httpMethod = "GET")
    public JSONResult queryReceivedMessagesList(){
        List<ReceivedMessages> logins = receivedMessagesService.queryReceivedMessagesList();
        return JSONResult.success("查询成功",logins);
    }

    /**
     * 新增接收消息表
     * @param receivedMessagesDto
     * @return
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增接收消息表",notes = "新增接收消息表",httpMethod = "POST")
    public JSONResult insert(@RequestBody ReceivedMessagesDto receivedMessagesDto){
        receivedMessagesService.insert(receivedMessagesDto);
        return JSONResult.success("保存成功");
    }

    /**
     * 修改接收消息表信息
     * @param receivedMessagesDto
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改接收消息表信息",notes = "修改接收消息表信息",httpMethod = "POST")
    public JSONResult update(@RequestBody ReceivedMessagesDto receivedMessagesDto){
        receivedMessagesService.update(receivedMessagesDto);
        return JSONResult.success("修改成功");
    }

    /**
     * 删除接收消息表信息
     * @param receivedId
     * @return
     */
    @PostMapping("delete/{id}")
    @ApiOperation(value = "删除接收消息表信息",notes = "删除接收消息表信息",httpMethod = "POST")
    public JSONResult delete(@PathVariable("receivedId") Long receivedId) {
        receivedMessagesService.delete(receivedId);
        return JSONResult.success("删除成功");
    }

    /**
     * 批量删除接收消息表信息
     * @param receivedIds
     * @return
     */
    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除接收消息表信息",notes = "批量删除接收消息表信息",httpMethod = "POST")
    public JSONResult deleteAll(@RequestBody List<Long> receivedIds) {
        receivedMessagesService.deleteBatch(receivedIds);
        return JSONResult.success("批量删除成功");
    }
}
